package com.neuedu.servlet;

import com.neuedu.entity.Admin;
import com.neuedu.service.AdminService;
import com.neuedu.service.impl.AdminServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/register")
public class RegisterServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String adminName=request.getParameter("adminName");//一定要于jsp文件里的name一致
        String password=request.getParameter("password");

        //获取用户的登录名以及密码用于service层的业务
        AdminService adminService=new AdminServiceImpl();
        Admin admin=new Admin();
        admin.setAdminName(adminName);
        admin.setPassword(password);
        if(adminService.register(admin))
        {
            response.sendRedirect("/registsuccess.jsp");
        }
        else {
            response.sendRedirect("/registfail.jsp");

        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
